package com.stm.web.controller.system;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stm.basicData.domain.KfToolsBox;
import com.stm.basicData.domain.SysWarnningConfig;
import com.stm.basicData.service.KfToolsBoxService;
import com.stm.basicData.service.KfToolsTypeService;
import com.stm.basicData.service.SysWarnningConfigService;
import com.stm.common.config.Global;
import com.stm.common.core.controller.BaseController;
import com.stm.common.utils.DateUtils;
import com.stm.framework.util.ShiroUtils;
import com.stm.synchronize.domain.DeviceSon;
import com.stm.synchronize.mapper.DeviceSonMapper;
import com.stm.system.domain.SysMenu;
import com.stm.system.domain.SysUser;
import com.stm.system.service.ISysConfigService;
import com.stm.system.service.ISysMenuService;
import com.stm.toolLedger.domain.KfTools;
import com.stm.toolLedger.domain.ToolsBoxDetail;
import com.stm.toolLedger.service.KfToolsService;
import com.stm.toolLedger.service.ToolsBoxDetailService;
import com.stm.toolsScrap.domain.KfToolsScrapApply;
import com.stm.toolsScrap.service.KfToolsScrapApplyService;
import com.stm.toolsTest.domain.KfToolsTestApply;
import com.stm.toolsTest.service.KfToolsTestApplyService;
import com.stm.web.controller.outandstorage.OutAndStorageRecordController;

import lombok.extern.slf4j.Slf4j;

/**
 * 首页 业务处理
 * 
 * @author admin
 */
@Slf4j
@Controller
public class SysIndexController extends BaseController
{
    @Autowired
    private ISysMenuService menuService;
    
    @Autowired
    private KfToolsBoxService kfToolsBoxService;
    
    @Autowired
    private DeviceSonMapper deviceSonMapper;
    
    // 系统首页
    @GetMapping("/index")
    public String index(ModelMap mmap)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        // 根据用户id取出菜单
        List<SysMenu> menus = menuService.selectMenusByUser(user);
        mmap.put("menus", menus);
        mmap.put("user", user);
        
        return "index";
    }
    
    
    @ResponseBody
    @PostMapping({"/getChartData"})
    public List<Map<String, Object>> getChartData(KfToolsBox kfToolsBox)
    {
    	return kfToolsBoxService.getChartData(kfToolsBox);
    }
    
    @ResponseBody
    @PostMapping({"/getLoadonline"})
    public List<Map<String, Object>> getLoadonline(KfToolsBox kfToolsBox)
    {
    	return kfToolsBoxService.getLoadonline(kfToolsBox);
    }
    
    @ResponseBody
    @PostMapping({"/getLoaddevice"})
    public List<DeviceSon> getLoaddevice(DeviceSon paramDeviceSon)
    {
    	return deviceSonMapper.getLoaddevice(paramDeviceSon);
    }

    // 地图
    @GetMapping("/system/main")
    public String main(ModelMap mmap,String dprtcode,String deptName)
    {
    	if(dprtcode!=null && !dprtcode.equals("")){
    		
    		mmap.put("dprtcode", dprtcode);
    		mmap.put("deptName", deptName);
    	}else{
    		// 取身份信息
    		SysUser user = ShiroUtils.getSysUser();
    		mmap.put("deptName", user.getDept().getDeptName());
    		mmap.put("dprtcode", user.getDeptId());
    	}
        return "dataV/main";
    }
    
    // 最大化地图
    @GetMapping("/system/maxmain")
    public String maxmain(ModelMap mmap,String dprtcode,String deptName)
    { 
		if(dprtcode!=null && !dprtcode.equals("")){
    		
    		mmap.put("dprtcode", dprtcode);
    		mmap.put("deptName", deptName);
    	}else{
    		// 取身份信息
    		SysUser user = ShiroUtils.getSysUser();
    		mmap.put("deptName", user.getDept().getDeptName());
    		mmap.put("dprtcode", user.getDeptId());
    	}
    	return "dataV/maxmain";
    }
    
    // 菜单导航
    @GetMapping("/system/account/{dprtcode}")
    public String account(@PathVariable("dprtcode") String dprtcode,ModelMap mmap,String name)
    {
    	
    	mmap.put("btname", name);
    	mmap.put("dprtcode", dprtcode);
    	return "dataV/account";
    }
    
    // 菜单导航检测
    @GetMapping("/system/accountjc/{dprtcode}")
    public String accountjc(@PathVariable("dprtcode") String dprtcode,ModelMap mmap,String name)
    {
    	
    	mmap.put("btname", name);
    	mmap.put("dprtcode", dprtcode);
    	return "dataV/accountjc";
    }
    // 检测明细
    @GetMapping("/system/accountjclist")
    public String accountjclist(ModelMap mmap)
    {
    	return "dataV/accountjclist";
    }
    
    // 台账明细
    @GetMapping("/system/accountlist")
    public String accountlist(ModelMap mmap)
    {
    	return "dataV/accountlist";
    }
    
    // 设备
    @GetMapping("/system/device")
    public String device(ModelMap mmap)
    {
    	return "dataV/device";
    }
    // 视频监控
    @GetMapping("/system/video")
    public String video(ModelMap mmap)
    {
    	return "dataV/video";
    }
    // 定位轨迹
    @GetMapping("/system/posit")
    public String posit(ModelMap mmap)
    {
    	return "dataV/posit";
    }
}
